package 代码记录.指定公司代码练习记录.西安.分值100分;

import java.util.*;

/**
 * @author zx
 * @create 2023-07-04 23:30
 * 人家的思路很棒，期待二刷
 * 这个题人家的思路有很多小细节
 */
public class 磁盘容量排序 {//27---copy(自己先做一下，不行就copy)
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] temp = new String[n];
        for(int i = 0;i < n;i++){
            temp[i] = sc.next();
        }
        Map<Integer,String> map = new HashMap<>();
        int[][] arr = new int[n][2];
        for(int i = 0;i < n;i++){
            int sum = 0;
            int index = -1;
            map.put(i + 1,temp[i]);
            for(int j = 0;j < temp[i].length();j++){
                if('M' == temp[i].charAt(j)){
                    sum += Integer.parseInt(temp[i].substring(index + 1, j));
                    index = j;
                }else if('G' == temp[i].charAt(j)){
                    sum += Integer.parseInt(temp[i].substring(index + 1, j)) * 1024;
                    index = j;
                }else if('T' == temp[i].charAt(j)){
                    sum += Integer.parseInt(temp[i].substring(index + 1, j)) * 1024 * 1024;
                    index = j;
                }
            }
            arr[i][0] = i + 1;
            arr[i][1] = sum;
        }
        Arrays.sort(arr, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o1[1] == o2[1] ? o1[0] - o2[0] : o1[1] - o2[1];
            }
        });
        for (int i = 0; i < n; ++i) {
            System.out.println(map.get(arr[i][0]));
        }
    }
}
